Scheduler for UWP では、カスタムデータソースに連結できます。NestedPropertySetter を使用して、AppointmentStorage.DataSource プロパティ設定することで、予定のプロパティと AppointmentStorage クラスの間のマッピングを設定します。
適切な参照と C1Scheduler コントロールが追加されているプロジェクトから始めます。
初期の名前空間宣言と XAML マークアップは、次のサンプルのようになります。
XAML |
コードのコピー
|
---|---|
<Page x:Class="ScheduleSamples.Samples.BusinessObjectsBinding" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:ScheduleSamples.Samples" xmlns:Schedule="using:C1.Xaml.Schedule" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Schedule:C1Scheduler x:Name="sched1" > </Schedule:C1Scheduler> </Grid> </Page> |
ページを右クリックし、コンテキストメニューから[コードの表示]を選択します。コードファイルが開いたら、名前空間宣言をチェックして、次のようになっていることを確認します。
C# |
コードのコピー
|
---|---|
using C1.C1Schedule; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.Serialization; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; |
次に、MainPage() コンストラクタを編集して、AppointmentCollection: にデモ用の予定を追加します。
C# |
コードのコピー
|
---|---|
public MainPage() AppointmentCollection apps = Resources["_ds"] as AppointmentCollection; |
次に、カスタム Appointment クラスと PropertyChangedEventHandler を追加します。
C# でコードを書く場合
C# |
コードのコピー
|
---|---|
[DataContract(Name = "Appointment", Namespace = "http://www.componentone.com")] private string _subject = ""; private string _location = ""; private DateTime _start; [DataMember] private TimeSpan _duration; private string _description = ""; private string _properties = ""; |
ObservableCollection を継承する AppointmentCollection クラスを追加します。
C# |
コードのコピー
|
---|---|
public class AppointmentCollection : ObservableCollection<Appointment> { public AppointmentCollection() { } } |
次に、MainPage.xaml ページでカスタムデータソースのインスタンスを作成します。ローカルリソースの Key 値に、先にコードで定義した名前を設定します。
XAML |
コードのコピー
|
---|---|
<Page.Resources> <local:AppointmentCollection x:Key="_ds"/> </Page.Resources> |
NestedPropertySetter を使用して、Appointment クラスで設定された予定のプロパティと AppointmentStorage クラスの間のマッピングを設定します。
XAML |
コードのコピー
|
---|---|
<c1:C1Scheduler x:Name="sched1" > <!-- AppointmentStorage をビジネスオブジェクトのコレクションにマップします --> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName" Value="Properties"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName" Value="Description"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName" Value="End"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName" Value="Id"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="Start"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataSource" Value="{Binding Mode=TwoWay, Source={StaticResource _ds}}" /> </c1:C1Scheduler> |
アプリケーションを実行すると、現在の日にマークが付いたテスト予定が表示されます。